﻿// Decompiled with JetBrains decompiler
// Type: XO1.XamlFileOperations
// Assembly: XO1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 8FC10D3F-5BDE-46BB-8E15-DDC98B50B0AE
// Assembly location: C:\Users\KasimGulcan\Desktop\Kosgeb\DynaCAD\Project\DynaCAD\bin\Debug\XO1.dll


using System;
using System.IO;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;

namespace XO1
{
    public static class XamlFileOperations
    {
        public static Canvas newOpenXaml(string xaml)
        {
            MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xaml));

            UIElement uiElement = (UIElement)XamlReader.Load(ms);
            
            if (uiElement is Viewbox)
            {
                if (((Decorator)uiElement).Child is Canvas)
                {
                    Canvas canvas = (Canvas)((Decorator)uiElement).Child;
                    ((Decorator)uiElement).Child = (UIElement)null;
                    return canvas;
                }
                int num = (int)MessageBox.Show("Dosya Açılamadı");
                return (Canvas)null;
            }
            if (uiElement is Canvas)
                return (Canvas)uiElement;
            else 
                return null;
        }

        public static Canvas OpenXaml(string FileName)
        {
            //if (!File.Exists(Directory.GetCurrentDirectory() + "\\license"))
            //{
            //    int num = (int)MessageBox.Show("Lisans Dosyası Mevcut Değil!");
            //    return (Canvas)null;
            //}
            //StreamReader streamReader = new StreamReader(Directory.GetCurrentDirectory() + "\\license");
            //string str = streamReader.ReadLine();
            //streamReader.Close();
            //string[] strArray = str.Split('-');
            //DateTime now = DateTime.Now;
            //DateTime dateTime;
            //try
            //{
            //    dateTime = new DateTime(Convert.ToInt32(strArray[0].Substring(4)), Convert.ToInt32(strArray[0].Substring(2, 2)), Convert.ToInt32(strArray[0].Substring(0, 2)));
            //}
            //catch
            //{
            //    int num = (int)MessageBox.Show("Geçersiz Lisans Dosyası!");
            //    return (Canvas)null;
            //}
            //if (!(Encrypt.GetString(strArray[0], strArray[1]) == strArray[2]))
            //{
            //    int num = (int)MessageBox.Show("Geçersiz Lisans Dosyası!");
            //    return (Canvas)null;
            //}
            //if (now > dateTime)
            //{
            //    int num = (int)MessageBox.Show("Lisans Süresi Dolmuştur!");
            //    return (Canvas)null;
            //}
            using (FileStream fileStream = new FileStream(FileName, FileMode.Open))
            {
                try
                {
                    UIElement uiElement = (UIElement)XamlReader.Load((Stream)fileStream);
                    if (uiElement is Viewbox)
                    {
                        if (((Decorator)uiElement).Child is Canvas)
                        {
                            Canvas canvas = (Canvas)((Decorator)uiElement).Child;
                            ((Decorator)uiElement).Child = (UIElement)null;
                            return canvas;
                        }
                        int num = (int)MessageBox.Show("Dosya Açılamadı");
                        return (Canvas)null;
                    }
                    if (uiElement is Canvas)
                        return (Canvas)uiElement;
                    int num1 = (int)MessageBox.Show("Dosya Açılamadı");
                    return (Canvas)null;
                }
                catch
                {
                    int num = (int)MessageBox.Show("Dosya Açılamadı");
                    return (Canvas)null;
                }
            }
        }
    }
}